﻿using System;
using System.Web;
using ASPNETVN.PORTAL.Components.UI;

namespace ASPNETVN.PORTAL
{
    public partial class AddEditPage : AddEditItemPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["page"] != null)
            {
                if (Request.QueryString["mid"] != null)
                {
                    // Obtain SiteSettings from Current Context
                    PortalDataSet ds = (PortalDataSet)HttpContext.Current.Items["PortalDataSet"];

                    // Find the appropriate Module in the Module table
                    PortalDataSet.ModuleRow moduleRow = ds.Module.FindByID(Convert.ToInt32(Request.QueryString["mid"]));

                    PortalDataSet.ModuleDefinitionRow moduledefineRow = ds.ModuleDefinition.FindByID(moduleRow.ModuleDefinitionID);
                    string sourceFile = moduledefineRow.SourceFile;
                    // Remove 'Main.ascx'
                    sourceFile = sourceFile.Substring(0, sourceFile.LastIndexOf('/'));
                    // Remove '~/'
                    sourceFile = sourceFile.Substring(2);
                    ContentPane.Controls.Add(Page.LoadControl(string.Format("~/{0}/Controls/{1}.ascx", sourceFile, Request.QueryString["page"])));
                }
            }            
        }
    }
}
